//// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
//package com.linqingying.gitcode.pullrequest.ui.filters
//
//import com.intellij.collaboration.async.launchNow
//import com.intellij.collaboration.ui.codereview.list.search.ReviewListQuickFilter
//import com.intellij.collaboration.ui.codereview.list.search.ReviewListSearchPanelViewModelBase
//import com.intellij.openapi.project.Project
//import kotlinx.coroutines.CoroutineScope
//import kotlinx.coroutines.FlowPreview
//import kotlinx.coroutines.flow.debounce
//import kotlinx.coroutines.flow.drop
//import kotlinx.coroutines.future.asDeferred
//import org.jetbrains.annotations.ApiStatus
//import com.linqingying.gitcode.api.data.GCLabel
//import com.linqingying.gitcode.api.data.GCUser
//import com.linqingying.gitcode.pullrequest.GCPRStatisticsCollector
//import com.linqingying.gitcode.pullrequest.data.service.GCPRRepositoryDataService
//import com.linqingying.gitcode.pullrequest.ui.filters.GCPRListQuickFilter.*
//
//@ApiStatus.Experimental
//class GCPRSearchPanelViewModel internal constructor(
//  scope: CoroutineScope,
//  private val project: Project,
//  private val repositoryDataService: GCPRRepositoryDataService,
//  historyViewModel: GCPRSearchHistoryModel,
//  currentUser: GCUser
//) :
//  ReviewListSearchPanelViewModelBase<GCPRListSearchValue, GCPRListQuickFilter>(
//    scope, historyViewModel,
//    emptySearch = GCPRListSearchValue.EMPTY,
//    defaultQuickFilter = AssignedToYou(currentUser)
//  ) {
//
//  override fun GCPRListSearchValue.withQuery(query: String?) = copy(searchQuery = query)
//
//  override val quickFilters: List<GCPRListQuickFilter> = listOf(
//    Open(currentUser),
//    YourPullRequests(currentUser),
//    AssignedToYou(currentUser),
//    ReviewRequests(currentUser)
//  )
//
//  val stateFilterState = searchState.partialState(GCPRListSearchValue::state) {
//    copy(state = it)
//  }
//
//  val authorFilterState = searchState.partialState(GCPRListSearchValue::author) {
//    copy(author = it)
//  }
//
//  val labelFilterState = searchState.partialState(GCPRListSearchValue::label) {
//    copy(label = it)
//  }
//
//  val assigneeFilterState = searchState.partialState(GCPRListSearchValue::assignee) {
//    copy(assignee = it)
//  }
//
//
//  val reviewFilterState = searchState.partialState(GCPRListSearchValue::reviewState) {
//    copy(reviewState = it)
//  }
//
//  init {
//    @OptIn(FlowPreview::class)
//    scope.launchNow {
//      // with debounce to avoid collecting intermediate state
//      searchState.drop(1).debounce(5000).collect {
//        GCPRStatisticsCollector.logListFiltersApplied(project, it)
//      }
//    }
//  }
//
//  suspend fun getAuthors(): List<GCUser> = repositoryDataService.collaborators.asDeferred().await()
//
//  suspend fun getAssignees(): List<GCUser> = repositoryDataService.issuesAssignees.asDeferred().await()
//  suspend fun getLabels(): List<GCLabel> = repositoryDataService.labels.asDeferred().await()
//}
//
//@ApiStatus.Experimental
//sealed class GCPRListQuickFilter(user: GCUser) : ReviewListQuickFilter<GCPRListSearchValue> {
//  protected val userLogin = user.login
//
//  data class Open(val user: GCUser) : GCPRListQuickFilter(user) {
//    override val filter = GCPRListSearchValue(state = GCPRListSearchValue.State.OPEN)
//  }
//
//  data class YourPullRequests(val user: GCUser) : GCPRListQuickFilter(user) {
//    override val filter = GCPRListSearchValue(state = GCPRListSearchValue.State.OPEN, author = userLogin)
//  }
//
//  data class AssignedToYou(val user: GCUser) : GCPRListQuickFilter(user) {
//    override val filter = GCPRListSearchValue(state = GCPRListSearchValue.State.OPEN, assignee = userLogin)
//  }
//
//  data class ReviewRequests(val user: GCUser) : GCPRListQuickFilter(user) {
//    override val filter = GCPRListSearchValue(
//      state = GCPRListSearchValue.State.OPEN,
//      reviewState = GCPRListSearchValue.ReviewState.AWAITING_REVIEW
//    )
//  }
//}
